package com.ruoyi.web.controller.yanglao;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.yanglao.YlOldHealth;
import com.ruoyi.system.service.yanglao.IYlOldHealthService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 老年养生Controller
 * 
 * @author ruoyi
 * @date 2024-06-14
 */
@Api("老年养生")
@RestController
@RequestMapping("/yanglao/oldHealth")
public class YlOldHealthController extends BaseController
{
    @Autowired
    private IYlOldHealthService ylOldHealthService;

    /**
     * 查询老年养生列表
     */
    @ApiOperation("查询老年养生列表")
    @PreAuthorize("@ss.hasPermi('yanglao:oldHealth:list')")
    @GetMapping("/list")
    public TableDataInfo list(YlOldHealth ylOldHealth)
    {
        startPage();
        List<YlOldHealth> list = ylOldHealthService.selectYlOldHealthList(ylOldHealth);
        return getDataTable(list);
    }

    /**
     * 导出老年养生列表
     */
    @ApiOperation("导出老年养生列表")
    @PreAuthorize("@ss.hasPermi('yanglao:oldHealth:export')")
    @Log(title = "老年养生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YlOldHealth ylOldHealth)
    {
        List<YlOldHealth> list = ylOldHealthService.selectYlOldHealthList(ylOldHealth);
        ExcelUtil<YlOldHealth> util = new ExcelUtil<YlOldHealth>(YlOldHealth.class);
        util.exportExcel(response, list, "老年养生数据");
    }

    /**
     * 获取老年养生详细信息
     */
    @ApiOperation("获取老年养生详细信息")
    @PreAuthorize("@ss.hasPermi('yanglao:oldHealth:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ylOldHealthService.selectYlOldHealthById(id));
    }

    /**
     * 新增老年养生
     */
    @ApiOperation("新增老年养生")
    @PreAuthorize("@ss.hasPermi('yanglao:oldHealth:add')")
    @Log(title = "老年养生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YlOldHealth ylOldHealth)
    {
        return toAjax(ylOldHealthService.insertYlOldHealth(ylOldHealth));
    }

    /**
     * 修改老年养生
     */
    @ApiOperation("修改老年养生")
    @PreAuthorize("@ss.hasPermi('yanglao:oldHealth:edit')")
    @Log(title = "老年养生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YlOldHealth ylOldHealth)
    {
        return toAjax(ylOldHealthService.updateYlOldHealth(ylOldHealth));
    }

    /**
     * 删除老年养生
     */
    @ApiOperation("删除老年养生")
    @PreAuthorize("@ss.hasPermi('yanglao:oldHealth:remove')")
    @Log(title = "老年养生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ylOldHealthService.deleteYlOldHealthByIds(ids));
    }
}
